package com.example.base.dto;

import lombok.Data;
import org.springframework.http.HttpStatus;

@Data
public class R<T> {

    private T data;

    private int code;

    private String msg;

    public static <T> R<T> success(T t) {
        R<T> ret = new R<>();
        ret.setData(t);
        ret.setCode(HttpStatus.OK.value());
        return ret;
    }

    public static <T> R<T> paramError(T t, String error) {
        R<T> ret = new R<>();
        ret.setData(t);
        ret.setCode(HttpStatus.BAD_REQUEST.value());
        ret.setMsg(error);
        return ret;
    }

    public static <T> R<T> error(T t, String error) {
        R<T> ret = new R<>();
        ret.setData(t);
        ret.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        ret.setMsg(error);
        return ret;
    }
}
